package com.bkgy.controller.rollPosImage.controller;

import com.bkgy.controller.rollPosImage.entity.RollPosImageRequest;
import com.bkgy.controller.rollPosImage.service.RollPosImageService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@Validated
@RestController
@RequestMapping("/rollPosImage")
@Tag(name = "工艺辊管理", description = "工艺辊信息及历史记录管理接口")
//@CrossOrigin(origins = "*", allowedHeaders = "*")
public class RollPosImageController {

    @Autowired
    private RollPosImageService rollPosImageService;

    @PostMapping("/rollInfoAndLogs")
    @Operation(summary = "获取工艺辊详细信息及历史记录",
            description = "获取工艺辊基本信息、点检历史和更换历史")
    public ResultData getRollInfoAndLogs(
            @Valid @RequestBody RollPosImageRequest request) {
        try {
            ResultData result = rollPosImageService.getRollByRequestInfo(request);
            return result;
        } catch (Exception e) {
            return ResultData.ResultDataFaultGd("获取工艺辊信息失败，请稍后重试", null);
        }
    }

    @PostMapping("/pendingList")
    @Operation(summary = "根据产线获取工艺辊列表",
            description = "根据产线编码获取该产线下的所有工艺辊列表")
    public ResultData listByLine(
            @Valid @RequestBody RollPosImageRequest request) {
        try {
            ResultData result = rollPosImageService.getRollListByRGroup(request);
            return result;
        } catch (Exception e) {
            return ResultData.ResultDataFaultGd("查询产线工艺辊列表失败，请稍后重试", null);
        }
    }
}